// API 类型使用示例
// 展示如何使用统一的API类型定义

import {
  // 车辆相关类型
  CreateCarRequest,
  UpdateCarRequest,
  GetCarsQuery,
  CarResponse,
  CreateCarResponse,
  GetCarsResponse,

  // 费用记录相关类型
  CreateExpenseRequest,
  UpdateExpenseRequest,
  GetExpensesQuery,
  ExpenseResponse,
  CreateExpenseResponse,

  // 收入记录相关类型
  CreateIncomeRequest,
  IncomeResponse,

  // 用户相关类型
  RegisterRequest,
  LoginRequest,
  UserResponse,
  LoginResponse,

  // 统计相关类型
  GetStatisticsQuery,
  StatisticsResponse,

  // 图表相关类型
  GetFuelTrendQuery,
  ChartDataResponse,

  // 配置相关类型
  SetSystemParamRequest,
  SystemParamResponse,

  // 通用类型
  ErrorResponse,
  SuccessResponse,
  PaginatedResponse,
} from './api';

// ==================== 车辆API使用示例 ====================

// 创建车辆请求示例
export const createCarExample: CreateCarRequest = {
  name: '我的爱车',
  category: '小汽车',
  brand: '丰田',
  carModel: '凯美瑞',
  productionTime: 1640995200000, // 2022-01-01
  purchaseTime: 1640995200000, // 2022-01-01
  vehicleType: 'fuel',
  licensePlate: '京A12345',
  notes: '我的第一辆车',
  currentMileage: 15000,
  fuelCapacity: 60,
  fuelType: '#95',
  purchasePrice: 250000,
  currency: 'CNY',
};

// 创建电车请求示例
export const createElectricCarExample: CreateCarRequest = {
  name: '我的电车',
  category: '电车',
  brand: '特斯拉',
  carModel: 'Model 3',
  productionTime: 1640995200000,
  purchaseTime: 1640995200000,
  vehicleType: 'electric',
  licensePlate: '京B67890',
  notes: '环保出行',
  currentMileage: 8000,
  batteryCapacity: 75,
  mileage: 500,
  purchasePrice: 350000,
  currency: 'CNY',
};

// 更新车辆请求示例
export const updateCarExample: UpdateCarRequest = {
  name: '我的爱车（已更新）',
  currentMileage: 20000,
  notes: '更新了里程数',
};

// 获取车辆列表查询示例
export const getCarsQueryExample: GetCarsQuery = {
  page: 1,
  limit: 10,
  category: '小汽车',
};

// 车辆响应示例
export const carResponseExample: CarResponse = {
  id: '507f1f77bcf86cd799439011',
  userId: '507f1f77bcf86cd799439012',
  name: '我的爱车',
  category: '小汽车',
  brand: '丰田',
  carModel: '凯美瑞',
  productionTime: 1640995200000,
  purchaseTime: 1640995200000,
  vehicleType: 'fuel',
  licensePlate: '京A12345',
  notes: '我的第一辆车',
  currentMileage: 15000,
  fuelCapacity: 60,
  fuelType: '#95',
  purchasePrice: 250000,
  currency: 'CNY',
  batteryCapacity: 0,
  mileage: 0,
  createdAt: '2024-01-01T00:00:00.000Z',
  updatedAt: '2024-01-01T00:00:00.000Z',
};

// 创建车辆响应示例
export const createCarResponseExample: CreateCarResponse = {
  success: true,
  message: '车辆创建成功',
  data: carResponseExample,
};

// 获取车辆列表响应示例
export const getCarsResponseExample: GetCarsResponse = {
  success: true,
  message: '获取车辆列表成功',
  data: [carResponseExample],
  pagination: {
    page: 1,
    limit: 10,
    total: 1,
    totalPages: 1,
  },
};

// ==================== 费用记录API使用示例 ====================

// 创建费用记录请求示例
export const createExpenseExample: CreateExpenseRequest = {
  vehicleId: '507f1f77bcf86cd799439011',
  type: '加油',
  mileage: 15000,
  fuelInfo: {
    showPrice: 7.5,
    actualPrice: 7.2,
    showAmount: 300,
    fuelAmount: 40,
    fuelType: '#95',
    discountAmount: 20,
    actualAmount: 268,
  },
  isFull: true,
  isRecord: false,
  isWarning: false,
  currency: 'CNY',
  date: '2024-01-01',
  notes: '加满油箱',
  location: '中石化加油站',
  odometer: 15000,
  description: '加满油箱',
  imageUrl: 'https://example.com/receipt.jpg',
};

// 更新费用记录请求示例
export const updateExpenseExample: UpdateExpenseRequest = {
  type: '保养',
  mileage: 16000,
  fuelInfo: {
    showPrice: 8.0,
    showAmount: 400,
    fuelAmount: 50,
    fuelType: '#95',
    discountAmount: 30,
    actualAmount: 370,
  },
  isFull: false,
  isRecord: true,
  isWarning: false,
  currency: 'CNY',
  date: '2024-01-15',
  notes: '定期保养',
  location: '4S店',
  odometer: 16000,
  description: '定期保养',
  imageUrl: 'https://example.com/maintenance.jpg',
};

// 获取费用记录列表查询示例
export const getExpensesQueryExample: GetExpensesQuery = {
  page: 1,
  limit: 10,
  vehicleId: '507f1f77bcf86cd799439011',
  type: '加油',
  startDate: '2024-01-01',
  endDate: '2024-01-31',
};

// 费用记录响应示例
export const expenseResponseExample: ExpenseResponse = {
  id: '507f1f77bcf86cd799439013',
  userId: '507f1f77bcf86cd799439012',
  vehicleId: '507f1f77bcf86cd799439011',
  type: '加油',
  mileage: 15000,
  fuelInfo: {
    showPrice: 7.5,
    actualPrice: 7.2,
    showAmount: 300,
    fuelAmount: 40,
    fuelType: '#95',
    discountAmount: 20,
    actualAmount: 268,
  },
  isFull: true,
  isRecord: false,
  isWarning: false,
  currency: 'CNY',
  date: '2024-01-01',
  notes: '加满油箱',
  location: '中石化加油站',
  odometer: 15000,
  description: '加满油箱',
  imageUrl: 'https://example.com/receipt.jpg',
  createdAt: '2024-01-01T00:00:00.000Z',
  updatedAt: '2024-01-01T00:00:00.000Z',
};

// 创建费用记录响应示例
export const createExpenseResponseExample: CreateExpenseResponse = {
  success: true,
  message: '费用记录创建成功',
  data: expenseResponseExample,
};

// ==================== 收入记录API使用示例 ====================

// 创建收入记录请求示例
export const createIncomeExample: CreateIncomeRequest = {
  vehicleId: '507f1f77bcf86cd799439011',
  type: '运营收入',
  amount: 5000,
  date: '2024-01-01',
  description: '网约车收入',
};

// 收入记录响应示例
export const incomeResponseExample: IncomeResponse = {
  id: '507f1f77bcf86cd799439014',
  userId: '507f1f77bcf86cd799439012',
  vehicleId: '507f1f77bcf86cd799439011',
  type: '运营收入',
  amount: 5000,
  date: '2024-01-01',
  description: '网约车收入',
  createdAt: '2024-01-01T00:00:00.000Z',
  updatedAt: '2024-01-01T00:00:00.000Z',
};

// ==================== 用户API使用示例 ====================

// 用户注册请求示例
export const registerExample: RegisterRequest = {
  username: 'testuser',
  email: 'test@example.com',
  password: 'password123',
  nickname: '测试用户',
};

// 用户登录请求示例
export const loginExample: LoginRequest = {
  username: 'testuser',
  password: 'password123',
};

// 用户响应示例
export const userResponseExample: UserResponse = {
  id: '507f1f77bcf86cd799439012',
  username: 'testuser',
  email: 'test@example.com',
  nickname: '测试用户',
  role: 'User',
  createdAt: '2024-01-01T00:00:00.000Z',
  updatedAt: '2024-01-01T00:00:00.000Z',
};

// 登录响应示例
export const loginResponseExample: LoginResponse = {
  success: true,
  message: '登录成功',
  data: {
    user: userResponseExample,
    token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
  },
};

// ==================== 统计API使用示例 ====================

// 获取统计数据查询示例
export const getStatisticsQueryExample: GetStatisticsQuery = {
  vehicleId: '507f1f77bcf86cd799439011',
  startDate: '2024-01-01',
  endDate: '2024-01-31',
  period: 'month',
};

// 统计数据响应示例
export const statisticsResponseExample: StatisticsResponse = {
  period: '2024-01',
  totalExpense: 1500,
  totalIncome: 5000,
  netExpense: -3500,
  fuelConsumption: 200,
  averageFuelConsumption: 8.5,
  totalDistance: 2000,
  averageDistance: 66.7,
  totalDiscount: 100,
  expenseBreakdown: {
    加油: 800,
    保养: 300,
    停车费: 200,
    保险: 200,
  },
};

// ==================== 图表API使用示例 ====================

// 获取油耗趋势查询示例
export const getFuelTrendQueryExample: GetFuelTrendQuery = {
  vehicleId: '507f1f77bcf86cd799439011',
  startDate: '2024-01-01',
  endDate: '2024-01-31',
};

// 图表数据响应示例
export const chartDataResponseExample: ChartDataResponse = {
  labels: ['1月', '2月', '3月', '4月', '5月', '6月'],
  datasets: [
    {
      label: '油耗趋势',
      data: [8.2, 8.5, 8.1, 7.9, 8.3, 8.0],
      backgroundColor: 'rgba(54, 162, 235, 0.2)',
      borderColor: 'rgba(54, 162, 235, 1)',
    },
  ],
};

// ==================== 配置API使用示例 ====================

// 设置系统参数请求示例
export const setSystemParamExample: SetSystemParamRequest = {
  key: 'default_currency',
  value: 'CNY',
  description: '默认货币设置',
};

// 系统参数响应示例
export const systemParamResponseExample: SystemParamResponse = {
  id: '507f1f77bcf86cd799439015',
  key: 'default_currency',
  value: 'CNY',
  description: '默认货币',
  createdAt: '2024-01-01T00:00:00.000Z',
  updatedAt: '2024-01-01T00:00:00.000Z',
};

// ==================== 错误响应示例 ====================

// 错误响应示例
export const errorResponseExample: ErrorResponse = {
  success: false,
  message: '请求参数错误',
  error: 'vehicleType is required',
};

// 成功响应示例
export const successResponseExample: SuccessResponse = {
  success: true,
  message: '操作成功',
};

// ==================== 分页响应示例 ====================

// 分页响应示例
export const paginatedResponseExample: PaginatedResponse<CarResponse> = {
  success: true,
  message: '获取车辆列表成功',
  data: [carResponseExample],
  pagination: {
    page: 1,
    limit: 10,
    total: 1,
    totalPages: 1,
  },
};

// ==================== 函数示例 ====================

// 模拟API调用函数示例
export async function createCarAPI(
  request: CreateCarRequest
): Promise<CreateCarResponse> {
  // 这里应该是实际的API调用
  console.log('创建车辆请求:', request);

  return {
    success: true,
    message: '车辆创建成功',
    data: carResponseExample,
  };
}

export async function getCarsAPI(
  query: GetCarsQuery
): Promise<GetCarsResponse> {
  // 这里应该是实际的API调用
  console.log('获取车辆列表查询:', query);

  return {
    success: true,
    message: '获取车辆列表成功',
    data: [carResponseExample],
    pagination: {
      page: query.page || 1,
      limit: query.limit || 10,
      total: 1,
      totalPages: 1,
    },
  };
}

export async function createExpenseAPI(
  request: CreateExpenseRequest
): Promise<CreateExpenseResponse> {
  // 这里应该是实际的API调用
  console.log('创建费用记录请求:', request);

  return {
    success: true,
    message: '费用记录创建成功',
    data: expenseResponseExample,
  };
}

export async function loginAPI(request: LoginRequest): Promise<LoginResponse> {
  // 这里应该是实际的API调用
  console.log('用户登录请求:', request);

  return {
    success: true,
    message: '登录成功',
    data: {
      user: userResponseExample,
      token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
    },
  };
}
